<template>
	<view class="tui-content-box">

		<view class="tui-box">
			<view class="withdraw-box">
				
				<view class="box-name">核销金额</view>
				<view class="box-input">
					<view class="ms">￥</view>
					<input placeholder-class="tui-phcolor" class="inputs" @input="inputMoney" placeholder="请输入核销金额"
						maxlength="11" type="text" />
				</view>
				<view class="box-name">备注</view>
				<view class="box-input">
					
					<input placeholder-class="tui-phcolor" class="inputs" placeholder="请输入备注"
						maxlength="11" type="text" />
				</view>
				
			</view>

			<view class="tui-btn-box">
				<tui-button shadow height="88rpx" shape="circle" type="danger" @click="btnSave()">提  交</tui-button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				error: true,
				withdraw: null,
				account: '',
				money: '',
				msg: null,
				account_id: '',
				accout_money:'',
				noClick: false,
				account_number: '',
				show: false,
				numberArr: [],
				pwdArr: ["", "", "", "", "", ""],
				temp: ["", "", "", "", "", ""],
				radius: false,
				currency_type: 4,
				array: [{
					name: '直推收益'
				}, {
					name: '共富收益'
				},{
					name: '区域收益'
				}],
				index: 1,
				account_money: 0,
				is_password: false,
			}
		},
		onLoad: function(options) {
			if (options.currency_type) {
				this.currency_type=options.currency_type
				this.index = options.currency_type == 4 ? 0 : 1;
			}
		},
		onShow() {
			this.tui.haslogin();
			if (this.tui.isLogin()) {
				this.init();
			}
		},
		onPullDownRefresh() {
			this.init();
		},
		methods: {
			init() {
				let token = this.tui.getToken();
				let account = this.tui.request('user', 'post', {
					token: token
				}, 1000, 1, '', 'userAccount');
				Promise.resolve(account).then((value) => {
					if (value.code == 200) {
						this.account = value.data;
					} 
				})
				// let password = this.tui.request('user', 'post', {
				// 	token: token
				// }, 1000, 1, '', 'hasPayPassword');
				// Promise.resolve(password).then((value) => {
				// 	if (value.code == 10000) {
				// 		this.is_password = value.data.istrue;
				// 	} 
				// })
				let bankaccount = {
					token: token,
					account_id: 'is_default'
				}
				let account_id = this.tui.request('user', 'post', bankaccount, 1000, 1, '', 'bankCart');
				Promise.resolve(account_id).then((value) => {
					if (value.code == 200) {
						if (value.data[0]) {
							this.account_id = value.data[0].id;
							if (value.data[0].account_type == 2) {
								this.account_number = value.data[0].alipayname;
							} else if (value.data[0].account_type == 1) {
								this.account_number = value.data[0].account_number;
							} else {
								this.account_number = value.data[0].weacht;
							}

						}


					} else {
						this.tui.toast(value.message);
					}
				})
			},
			bindPickerChange: function(e) {
				this.index = e.detail.value;

				switch (this.index) {
					case 0:
						this.currency_type =2
						this.account_money=this.account.balance
						break;
					case 1:
						this.currency_type = 4
						this.account_money=this.account.team_balance
						break;
						case 2:
							this.currency_type = 6
							this.account_money=this.account.service_balance
							break;
					default:
						break;
				}

			},
			switchKeyboard(index) {
				let length = index; //e.currentTarget.dataset.length;
				let arr = ["", "", "", "", "", ""]
				let radius = false
				if (length == 4) {
					arr = ["", "", "", ""]
					radius = true
				}
				this.pwdArr = arr;
				this.temp = arr;
				this.numberArr = [];
				this.radius = radius;
				this.show = true;
			},
			closeKeyboard: function() {
				this.show = false;
				this.numberArr = [];
				this.pwdArr = this.temp
			},
			getPwd: function() {
				//判断并取出密码
				
				if (this.numberArr.length === this.pwdArr.length) {
					uni.showLoading({
						title: '提交申请',
						mask: true
					})
					setTimeout(() => {
						let pwd = this.numberArr.join('')
						this.closeKeyboard();
						let token = this.tui.getToken();
						let datas = {
							token: token,
							account_id: this.account_id,
							money: this.money,
							pay_password: pwd,
							currency_type: this.currency_type,
						}
						let account = this.tui.request('user', 'post', datas, 1000, 1, '', 'withdraw');
						Promise.resolve(account).then((value) => {
							if (value.code == 10000) {
								this.tui.toast(value.message);
								setTimeout(() => {
									uni.navigateTo({
										url: '../user/withdraw'
									});
								}, 1000)
							} else {
								this.noClick = false;
								this.tui.toast(value.message);
							}
						})
					}, 800);
				}
			},
			keyboardClick: function(e) {
				let numberArr = this.numberArr;
				let pwdArr = this.pwdArr;
				let index = e.index;
				if (numberArr.length === pwdArr.length || index == undefined) {
					return;
				}
				if (index == 9) { //取消键
					this.closeKeyboard();
					this.noClick = false;
					return;
				} else if (index == 11) {
					//退格键
					let len = numberArr.length;
					if (len) {
						pwdArr.splice(len - 1, 1, "");
					} else {
						pwdArr = this.temp;
					}
					numberArr.pop()
				} else if (index == 10) {
					numberArr.push(0);
					pwdArr.splice(numberArr.length - 1, 1, "●");
				} else {
					numberArr.push(index + 1);
					pwdArr.splice(numberArr.length - 1, 1, "●");
				}
				this.numberArr = numberArr;
				this.pwdArr = pwdArr;
				this.getPwd();
			},
			inputMoney: function(e) {
				this.money = e.detail.value;
			},
			addAccount() {
				uni.navigateTo({
					url: '../myBank/bankList'
				});
			},
			btnSave() {
				uni.hideLoading();
				if (!this.account_id) {
					this.tui.toast('请先添加提现账号');
					return false;
				}
				if (this.noClick == true) {
					this.tui.toast('请勿重复提交');
					return false;
				}
				if (this.money == '') {
					this.tui.toast('提现金额不能为空');
					return false;
				}
				this.noClick = true;
				if(this.is_password!=true){
					this.tui.toast('支付密码还未设置,正在为您跳转。。。');
					setTimeout(() => {
						uni.navigateTo({
							url: '../userInfo/setPayPassword'
						});
					}, 2000);
					return;
				}
				this.switchKeyboard(6);
			},
			waterList() {
				uni.navigateTo({
					url: '../user/withdrawal'
				})
			}
		}
	}
</script>

<style>
	page {
		background-color: #F5F5F5;
	}

	.tui-content-box {
		width: 100%;
		padding: 0 30rpx;
		box-sizing: border-box;
		position: relative;
		/* 	top: -72rpx; */
		z-index: 10;
	}

	.tui-keyboard-tips {
		width: 100%;
		height: 120rpx;
		line-height: 1;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 30rpx;
		background: #fff;
		position: relative;
		color: #333;
		border: 0;
	}

	.tui-digital-box {
		background: #fff;
		padding-bottom: 50rpx;
		border: 0;
	}

	.input-select {
		font-size: 30rpx;
		color: #858680
	}

	.tui-box {
		/* 	width: 100%; */
		margin-top: 30rpx;
		background: #fff;
		padding: 36rpx;
		box-shadow: 0 3rpx 20rpx rgba(183, 183, 183, 0.1);
		border-radius: 10rpx;
		overflow: hidden;
	}

	.tui-btn-box {
		margin-bottom: 20rpx;
	}

	.withdraw-account {
		display: flex;
		box-sizing: border-box;
		align-items: center;
		padding: 10rpx;
		justify-content: center;
		background: #eaeaea;
		height: 100rpx;
		border-radius: 10rpx;
		text-align: center;
		line-height: 100rpx;
		color: #4e4d4d;
	}

	.withdraw-account-h1 {
		color: #4e4d4d;
		font-weight: bold;
		display: flex;
		box-sizing: border-box;
		align-items: center;
		justify-content: center;
		font-size: 30rpx;
	}

	.withdraw-box {
		margin-top: 40rpx;
	}

	.box-name {
		font-size: 26rpx;
		color: #3e3e3e;
	}

	.box-input {
		border-bottom: 1rpx solid #f3f2f2;
		display: flex;
		height: 100rpx;
		line-height: 100rpx;
		align-items: center;
		padding: 10rpx;
		margin-bottom: 30rpx;
		justify-content: left;
		font-size: 60rpx;
	}

	.box-input .ms {}

	.box-input .inputs {
		height: 60rpx;
		font-size: 60rpx;
	}

	.box-notice {
		font-size: 24rpx;
		color: #8e8d8d;
		margin-bottom: 60rpx;
	}

	.withdraw-nums {
		color: #f23030;
		display: inline;
	}

	.withdraw-txt {
		margin-top: 40rpx;
		margin-left: 20rpx;
		color: #bbb9b0;
		font-size: 22rpx;
		line-height: 44rpx;
	}
</style>
